package com.lighting.shortlink.project.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 数据库持久层配置类
 * @author : lighting
 */
@Configuration
public class DataBaseConfiguration {
    /**
     * MybatisPlus拦截器 增强功能
     * 分页插件
     */
    @Bean
    @ConditionalOnMissingBean //当前容器中没有此 bean 才加载，有就不加载了，保证 bean的单例
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//       添加一个分页拦截器
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return interceptor;
    }
}
